package User;
import Manager.Product;
import java.util.ArrayList;
import java.util.List;
public class Cart {
    public List<Product> products = new ArrayList<>();
    public void addProduct(Product product) {
        if (product.stock > 0){
            products.add(product);
            product.stock--;
            System.out.println("已加入购物车: " + product.name);
            product.num++;
        }
        else {
            System.out.println("库存不足，无法添加: " + product.name);
        }
    }
    public void removeProduct(Product product){
        if (products.contains(product)){
            products.remove(product);
            product.stock++;
            System.out.println("已从购物车移除: " + product.name);
            product.num--;
        } else{
            System.out.println("购物车中没有该商品: " + product.name);
        }
    }
    public void showCart() {
        System.out.println("购物车:");
        if (products.isEmpty()) {
            System.out.println("购物车为空");
        } else {
            for (Product product : products) {
                System.out.println(product.name + " - ¥" + product.price);
            }
        }
    }
}
